#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    db = new dataBase();
    ui->label_3->hide(); // 隐藏 label
    ui->lineEdit->hide();

}

MainWindow::~MainWindow()
{
    delete db;
    delete ui;
}

void MainWindow::on_login_clicked()
{
    QString userID = ui->username->text();
    QString passwd = ui->passwd->text();

    QString fileName = ui->lineEdit->text();
    QStringList list=fileName.split("\\", Qt::SkipEmptyParts);
    QString newFileName;
    foreach (QString tag, list) {
        newFileName = newFileName + "/" + tag;
    }

    if(ui->default_2->isChecked()){
        if(passwd == db->query_userPassed(userID)){
            //user *u = new user(userID);
            user *u = new user("config.txt",userID);
            u->show();
            this->close();
        }else{
            QMessageBox::warning(this,"错误","账户或密码错误");
        }
    }else{
        if(passwd == db->query_userPassed(userID)){
            //user *u = new user(userID);
            user *u = new user(newFileName,userID);
            u->show();
            this->close();
        }else{
            QMessageBox::warning(this,"错误","账户或密码错误");
        }
    }
}


void MainWindow::on_pushButton_2_clicked()
{
    this->close();
}

void MainWindow::on_default_2_stateChanged(int arg1)
{
    // 如果 QCheckBox 被选中，隐藏 label；否则显示 label
    if (arg1 == Qt::Checked) {
        ui->label_3->hide(); // 隐藏 label
        ui->lineEdit->hide();
    } else {
        ui->label_3->show(); // 显示 label
        ui->lineEdit->show();
    }
}

